package djboom.materials.display.elements {
	import org.casalib.display.CasaSprite;

	import flash.events.Event;
	import flash.events.MouseEvent;

	/**
	 * Базовый класс для различных простых объектов.
	 * <br>
	 * 
	 * @author DJ BooM 
	 * @since 26.05.2010
	 * 
	 */

	public class SimpleSmartSprite extends CasaSprite {

		// ----------------------------------------------------------------------------
		// Константы класса.
		// ----------------------------------------------------------------------------
		
		// ----------------------------------------------------------------------------
		// Свойства класса.
		// ----------------------------------------------------------------------------
	
		// ----------------------------------------------------------------------------
		// Конструктор.
		// ----------------------------------------------------------------------------

		public function SimpleSmartSprite() {
			super();
			
			addEventListener(Event.ADDED_TO_STAGE, initSprite);
			addEventListener(Event.REMOVED_FROM_STAGE, clearContent);
		}

		// ----------------------------------------------------------------------------
		// Методы класса.
		// ----------------------------------------------------------------------------
		
		// ----------------------------------------------------------------------------
		// Публичные методы.
		// ----------------------------------------------------------------------------

		public function initSprite(event:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, initSprite);
		}

		public function clearContent(event:Event):void {
			removeEventListener(Event.REMOVED_FROM_STAGE, clearContent);
		}

		override public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void {
			super.addEventListener(type, listener, useCapture, priority, useWeakReference);
			
			if (type == MouseEvent.CLICK || type == MouseEvent.ROLL_OVER || type == MouseEvent.MOUSE_OVER || type == MouseEvent.MOUSE_DOWN) {
				this.buttonMode = true;
				this.useHandCursor = true;
			}
		}

		override public function removeEventListeners():void {
			super.removeEventListeners();
			
			this.buttonMode = false;
			this.useHandCursor = false;
		}

		override public function removeEventsForType(type:String):void {
			super.removeEventsForType(type);
			
			if (type == MouseEvent.CLICK || type == MouseEvent.ROLL_OVER || type == MouseEvent.MOUSE_OVER || type == MouseEvent.MOUSE_DOWN) {
				this.buttonMode = false;
				this.useHandCursor = false;
			}
		}

		override public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void {
			super.removeEventListener(type, listener, useCapture);
			
			if (type == MouseEvent.CLICK || type == MouseEvent.ROLL_OVER || type == MouseEvent.MOUSE_OVER || type == MouseEvent.MOUSE_DOWN) {
				this.buttonMode = false;
				this.useHandCursor = false;
			}
		}
			
		// ----------------------------------------------------------------------------
		// Методы доступа.
		// ----------------------------------------------------------------------------
	}
}
